package com.JingYan.elasticSearch.controller;

import com.JingYan.annotation.BaseResponse;
import com.JingYan.elasticSearch.domain.Book;
import com.JingYan.elasticSearch.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author DongJiaQi
 * @create 2022/11/28 16:56
 * @Description:
 */
@RestController
@BaseResponse
public class BookController {
    @Autowired
    BookService bookService;

    @PostMapping("/book")
    public Book addBook(@RequestBody Book book){
        bookService.addBook(book);
        Map<String,String> map = new HashMap<>();
        return book;
    }
    @GetMapping("/book/search")
    public List<Book> search(String key){
        return bookService.searchBook(key);
    }
    @GetMapping("/book/search1")
    public SearchHits<Book> search1(String key){
        return bookService.searchBook1(key);
    }
}
